<template>
  <div class="shelfno">
    <el-card>
      <div class="title">排架号管理</div>
      <el-form
        ref="formRef"
        :model="formValue"
        label-width="auto"
      >
        <el-form-item
          v-for="item in formList"
          :label="item.label"
          :prop="item.prop"
          :rules="[
            {
              required: true,
              message: item.label + '不能为空！',
              trigger: ['blur', 'change'],
            },
          ]"
        >
          <el-input
            v-model="formValue[item.prop]"
            style="max-width: 600px"
            placeholder="请输入排架号"
          >
          </el-input>
        </el-form-item>
        <el-form-item>
          <div class="w-full flex items-center justify-center">
            <el-button
              type="primary"
              @click="submitForm(formRef)"
            >
              提交
            </el-button>
            <el-button @click="resetForm(formRef)">重置</el-button>
          </div>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script setup>
const formRef = ref();
const formValue = ref({});
const formList = ref([
  { label: "条码号", prop: "barcode", value: "" },
  { label: "排架号", prop: "shelfNo", value: "" },
]);

const submitForm = async (formEl) => {
  if (!formEl) return;
  await formEl.validate((valid, fields) => {
    if (valid) {
      ElMessage.warning("暂未查询到排架号！");
      console.log("submit!");
    } else {
      console.log("error submit!", fields);
    }
  });
};

const resetForm = (formEl) => {
  if (!formEl) return;
  formEl.resetFields();
};
</script>

<style lang="scss" scoped>
.shelfno {
  max-width: 600px;
  margin: 0 auto;

  border-radius: 8px;
  box-sizing: border-box;

  .title {
    text-align: center;
    font-weight: bold;
    font-size: 24px;
    margin-bottom: 20px;
  }
}
</style>
